前言

大學時候一直沒辦法學好這個被教授屢屢稱為trivial的科目。 這個系列文章我們將以淺入淺出的原則幫作者複習一些機率的概念。


In [ ]:

題1 我是不是該去看醫生

這個是個簡單的機率問題。假定有個醫學界阿宅檢定號稱通過考試的阿宅有95%的機率是個阿宅,而當前人口有99.9%是正常人。 請問 1.)隨便抓一個人去檢驗而出現陽性反應的機率有多少? $${ P}(B)={ P}(A){ P}(B\mid A)+{ P}(A^ c){ P}(B\mid A^ c) =0.001 \cdot 0.95 + 0.999 \cdot 0.05 =0.0509.$$


In [5]:
pa = 0.001
pbga = 0.95
pac = 1-pa
pbgac = 0.05
print "Total probability of P(B) is " + \
        str(0.001*0.95 + 0.05* 0.999)


Total probability of P(B) is 0.0509

你被檢出,但妳趁的事

$${ P}(A\mid B)=\frac{{ P}(A){ P}(B\mid A)}{{ P}(B)} =\frac{0.001 \cdot 0.95}{0.0509} \approx 0.01866.$$

In [2]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import mpld3

mpld3.enable_notebook()

In [3]:
fig, ax = plt.subplots(subplot_kw=dict(axisbg='#EEEEEE'))
ax.grid(color='white', linestyle='solid')

N = 50
scatter = ax.scatter(np.random.normal(size=N),
                     np.random.normal(size=N),
                     c=np.random.random(size=N),
                     s = 1000 * np.random.random(size=N),
                     alpha=0.3,
                     cmap=plt.cm.jet)

ax.set_title("D3 Scatter Plot", size=18);


/Users/michael/anaconda/lib/python2.7/site-packages/IPython/core/formatters.py:92: DeprecationWarning: DisplayFormatter._ipython_display_formatter_default is deprecated: use @default decorator instead.
  def _ipython_display_formatter_default(self):
/Users/michael/anaconda/lib/python2.7/site-packages/IPython/core/formatters.py:669: DeprecationWarning: PlainTextFormatter._singleton_printers_default is deprecated: use @default decorator instead.
  def _singleton_printers_default(self):

A test for a certain rare disease is assumed to be correct 95% of the time: if a person has the disease, the test result is positive with probability 0.95, and if the person does not have the disease, the test result is negative with probability 0.95. A person drawn at random from a certain population has probability 0.001 of having the disease. Find the probability that a random person tests positive. Given that the person just tested positive, what is the probability he actually has the disease?